package test;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class Avion extends BasicGame{
	
	
	
	Image land = null;
	Image plane = null;
	float x = 400;
	float y = 300;
	float scale = 1.0f;
	
	
	
	
	
	
	
	
	
	
	public Avion() {
		super("jeu d'avion");
		
	}

	@Override
	public void init(GameContainer container) throws SlickException 
	{
		land = new Image("res/images/land.jpg");
		plane = new Image("res/images/avion.png");
	}

	@Override
	public void update(GameContainer container, int delta)
			throws SlickException {
		Input input = container.getInput();
		 
        if(input.isKeyDown(Input.KEY_A))
        {
            plane.rotate(-0.2f * delta);
        }
 
        if(input.isKeyDown(Input.KEY_D))
        {
            plane.rotate(0.2f * delta);
        }
 
        if(input.isKeyDown(Input.KEY_W))
        {
            float hip = 0.4f * delta;
 
            float rotation = plane.getRotation();
 
            x+= hip * java.lang.Math.sin(java.lang.Math.toRadians(rotation));
            y-= hip *java.lang.Math.cos(java.lang.Math.toRadians(rotation));
        }
 
        if(input.isKeyDown(Input.KEY_2))
        {
            scale += (scale >= 5.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
        }
        if(input.isKeyDown(Input.KEY_1))
        {
            scale -= (scale <= 1.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
        }
		
	}

	@Override
	public void render(GameContainer arg0, Graphics arg1) throws SlickException {
		
		land.draw(0, 0);
		plane.draw(x, y, scale);
	}

}
